﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace PL_TileEditor
{
    public partial class EnemyMaker : Form
    {
        public EnemyMaker()
        {
            InitializeComponent();

        }

        private void loadSheetToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                enemyViewer1.EnemySheet = (Bitmap)(Bitmap.FromFile(openFileDialog1.FileName));
                toolStripLabel1.Text = openFileDialog1.FileName;
                enemyViewer1.EnemySize = new Size(enemyViewer1.EnemySheet.Size.Width / 4, enemyViewer1.EnemySheet.Size.Height / 2);
                nudFrameWidth.Value = (int)(enemyViewer1.EnemySheet.Size.Width / 4);
                nudFrameHeight.Value = (int)(enemyViewer1.EnemySheet.Size.Height / 2);
            }
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            enemyViewer1.Frame += 1;
            if (enemyViewer1.Frame > 2)
                enemyViewer1.Frame = 0;
            enemyViewer1.Invalidate();
        }

        private void numericUpDown1_ValueChanged(object sender, EventArgs e)
        {
            enemyViewer1.EnemySize.Width = (int)nudFrameWidth.Value;
            enemyViewer1.Invalidate();
        }

        private void numericUpDown2_ValueChanged(object sender, EventArgs e)
        {
            enemyViewer1.EnemySize.Height = (int)nudFrameHeight.Value;
            enemyViewer1.Invalidate();
        }

        private void numericUpDown3_ValueChanged(object sender, EventArgs e)
        {
            enemyViewer1.CollisionRectangle.Width = (int)nudCollisionWidth.Value;
            enemyViewer1.CollisionRectangle.X = enemyViewer1.EnemySize.Width / 2 - enemyViewer1.CollisionRectangle.Width / 2;
            enemyViewer1.Invalidate();
        }

        private void numericUpDown4_ValueChanged(object sender, EventArgs e)
        {
            enemyViewer1.CollisionRectangle.Height = (int)nudCollisionHeight.Value;
            enemyViewer1.CollisionRectangle.Y = enemyViewer1.EnemySize.Height - enemyViewer1.CollisionRectangle.Height;
            enemyViewer1.Invalidate();
        }

        private void numericUpDown5_ValueChanged(object sender, EventArgs e)
        {

        }

        private void numericUpDown6_ValueChanged(object sender, EventArgs e)
        {

        }

        private void textBox2_TextChanged(object sender, EventArgs e)
        {

        }

        private void sToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (saveFileDialog1.ShowDialog() == DialogResult.OK)
            {
                FileStream tempFile;
                tempFile = new FileStream(saveFileDialog1.FileName, FileMode.Create);
                BinaryWriter bw = new BinaryWriter(tempFile);

                bw.Write(tbName.Text);
                bw.Write(Path.GetFileName(toolStripLabel1.Text));
                bw.Write(tbClass.Text);
                bw.Write(tbSpecies.Text);
                bw.Write(cbElement.SelectedItem.ToString());
                bw.Write(nudFrameWidth.Value);
                bw.Write(nudFrameHeight.Value);
                bw.Write(nudCollisionWidth.Value);
                bw.Write(nudCollisionHeight.Value);
                bw.Write(nudLevel.Value);
                bw.Write(nudHP.Value);
                bw.Write(nudStr.Value);
                bw.Write(nudDef.Value);
                bw.Write(nudAgi.Value);
                bw.Write(nudInt.Value);
                bw.Write(lbLoot.Items.Count);
                for (int i = 0; i < lbLoot.Items.Count; i++)
                {
                    //bw.Write(lbLoot.Items[i]
                }


                tempFile.Close();
            }

        }
    }
}
